package diseaseandcureadministration.symptom;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

import diseaseandcureadministration.AbstractLoader;
import diseaseandcureadministration.registry.Registrable;

public class SymptomsFileLoader extends AbstractLoader {
		
	public SymptomsFileLoader()
	{
		setFileName("data\\symptoms.txt");
	}
	
	@Override
	public ArrayList<Registrable> load() throws FileNotFoundException
	{
		ArrayList<Registrable> symptoms = new ArrayList<Registrable>();
		Symptom symptom;
		
		File symptomsFile = new File(getFileName());
		Scanner scanner = new Scanner(symptomsFile);
			
		while(scanner.hasNextLine())
		{
			String line = scanner.nextLine();
			
			int positionOfComma = line.indexOf(',');
			String name = line.substring(0, positionOfComma);

			int positionOfSeverity = positionOfComma + 2;
			String severityAsString = line.substring(positionOfSeverity).toUpperCase().replaceAll(" ", "");			
			SymptomSeverity severity = SymptomSeverity.valueOf(severityAsString);
			
			symptom = new Symptom(name, severity);
			symptoms.add(symptom);				
		} 		
		
		scanner.close();	
		
		return symptoms;		
	}
	
}
